package com.kgc.scd.controller;

import com.kgc.scd.annotation.RequestPermission;
import com.kgc.scd.annotation.RequestUser;
import com.kgc.scd.contant.CommonConstant;
import com.kgc.scd.service.BuyVipService;
import com.kgc.scd.util.MyUtils;
import com.kgc.scd.util.UserAnno;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

/**
 * Created On : 2022/6/16.
 * <p>
 * Author     : 15950526365
 * <p>
 * Description: 购买会员操作入口
 */
@RestController
@Slf4j
public class BuyVipController {

    @Autowired(required = false)
    private BuyVipService buyVipService;

    public String generateOrderId(){
        // 生成用户ID的组成规则：系统标识+时间字符串+随机序列号
        return "V"
                + LocalDateTime.now().format(DateTimeFormatter.ofPattern(CommonConstant.TIME_PATTERN_MINUTE))
                + MyUtils.generateNonceStrUseUUID(4);
    }

    @PostMapping("/placeVipOrder")
    public Map<String, Object> placeVipOrder(@RequestParam String userId){
        Map<String, Object> results = new HashMap<>();
        String vipOrderId = generateOrderId();
        log.info("user:{},vipOrderId:{}",userId,vipOrderId);
        buyVipService.addVipOrder(vipOrderId,userId);
        results.put("orderId:",vipOrderId);
        results.put("userId:",userId);
        return results;
    }



}
